#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    void moveZeroes(vector<int>& nums)
    {
        int cur = 0, prev = -1;
        while (cur < nums.size())
        {
            if (nums[cur])
            {
                prev++;
                swap(nums[prev], nums[cur]);
                cur++;
            }
            else
            {
                cur++;
            }
        }
    }
};

class Solution {
public:
    void duplicateZeros(vector<int>& arr)
    {
        int cur = 0, prev = -1;
        int n = arr.size();
        while (cur < n)
        {
            if (arr[cur]) prev++;
            else prev += 2;
            if (prev >= n - 1) break;
            cur++;
        }
        if (prev >= n)
        {
            arr[n - 1] = 0;
            prev -= 2;
            cur -= 1;
        }
        while (cur >= 0)
        {
            if (arr[cur]) arr[prev--] = arr[cur--];
            else
            {
                arr[prev--] = 0;
                arr[prev--] = 0;
                cur--;
            }
        }
    }
};
class Solution {
public:
    int change(int num)
    {
        int tmp = 0;
        while (num)
        {
            int x = num % 10;
            tmp += x * x;
            num /= 10;
        }
        return tmp;
    }
    bool isHappy(int n) {
        int low = n, fast = change(n);
        while (low != fast)
        {
            low = change(low);
            fast = change(fast);
            fast = change(fast);
        }
        if (low == 1) return true;
        return false;
    }
};